/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.zb.hms.base.util.logUtil;

import com.zb.hms.base.util.dateUtil.DateFormat;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;


/**
 *
 * @author Administrator
 */
@Component
@SuppressWarnings(value="static-access")
public  class ErrorLog {
    @Resource
    private  DateFormat dateFormat;
    private String path;
    public void setPath(String path){
        this.path=path;
    }
    public static ErrorLog getInstance(){
        return new ErrorLog();
    }
    public void print(String msg) {
        FileWriter fileWriter=null;
        try {
            File file=new File(path);
            if(file.getParentFile().exists())
                file.getParentFile().mkdirs();
            fileWriter = new FileWriter(file, true);
            fileWriter.write(dateFormat.getTime("yyyy年MM月dd日 HH:mm:ss")+"\t:\t"+msg+"\n");
        } catch (IOException ex) {
            Logger.getLogger(ErrorLog.class.getName()).log(Level.INFO, null, ex);
        } finally {
            try {
                fileWriter.close();
            } catch (IOException ex) {
                Logger.getLogger(ErrorLog.class.getName()).log(Level.INFO, null, ex);
            }
        }
    }
}
